package com.ruoyi.fetv.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.fetv.domain.FetvInformation;
import com.ruoyi.fetv.mapper.FetvSchoolMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fetv.domain.FetvSchool;
import com.ruoyi.fetv.service.IFetvSchoolService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学校Controller
 *
 * @author éé­æ°
 * @date 2023-02-24
 */
@CrossOrigin(origins = "http://ruoyi.vip", maxAge = 3600)
@RestController
@RequestMapping("/fetv/school")
public class FetvSchoolController extends BaseController {
    @Resource
    private IFetvSchoolService fetvSchoolService;

    @Resource
    private FetvSchoolMapper fetvSchoolMapper;

    /**
     * 查询学校列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(FetvSchool fetvSchool) {
        startPage();
        List<FetvSchool> list = fetvSchoolService.selectFetvSchoolList(fetvSchool);
        return getDataTable(list);
    }

    /**
     * 导出学校列表
     */
    @Anonymous
    //@Log(title = "学校", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FetvSchool fetvSchool) {
        List<FetvSchool> list = fetvSchoolService.selectFetvSchoolList(fetvSchool);
        ExcelUtil<FetvSchool> util = new ExcelUtil<FetvSchool>(FetvSchool.class);
        util.exportExcel(response, list, "学校数据");
    }

    /**
     * 获取学校详细信息
     */
    @Anonymous
    @GetMapping(value = "/{schoolId}")
    public AjaxResult getInfo(@PathVariable("schoolId") Integer schoolId) {
        return success(fetvSchoolService.selectFetvSchoolBySchoolId(schoolId));
    }

    /**
     * 新增学校
     */
    @Anonymous
    //@Log(title = "学校", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FetvSchool fetvSchool) {
        return toAjax(fetvSchoolService.insertFetvSchool(fetvSchool));
    }

    /**
     * 修改学校
     */
    @Anonymous
    //@Log(title = "学校", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FetvSchool fetvSchool) {
        return toAjax(fetvSchoolService.updateFetvSchool(fetvSchool));
    }

    /**
     * 删除学校
     */
    @Anonymous
    //@Log(title = "学校", businessType = BusinessType.DELETE)
    @DeleteMapping("/{schoolIds}")
    public AjaxResult remove(@PathVariable Integer[] schoolIds) {
        return toAjax(fetvSchoolService.deleteFetvSchoolBySchoolIds(schoolIds));
    }

    /**
     * 根据ID修改学校状态
     *
     * @param schoolId
     * @return
     */
    @Anonymous
    @GetMapping("/status")
    public AjaxResult editStatusById(@RequestParam Integer schoolId, @RequestParam int status) {
        FetvSchool fetvSchool = fetvSchoolMapper.selectFetvSchoolBySchoolId(schoolId);
        fetvSchool.setStatus(status);
        return toAjax(fetvSchoolService.updateFetvSchool(fetvSchool));
    }
}
